// Author: wsfuyibing <682805@qq.com>
// Date: 2025-03-28

package config

import (
	"gitee.com/go-libs/config"
	"strings"
)

const (
	DefaultGinMode = "release"
)

// GinConfig
// Gin框架配置.
//
//	framework.Application.GinConfig()
type GinConfig struct {
	ContextWithFallback   bool `yaml:"context_with_fallback"`
	ForwardedByClientIP   bool `yaml:"forwarded_by_client_ip"`
	MethodNotAllowed      bool `yaml:"method_not_allowed"`
	RedirectFixedPath     bool `yaml:"redirect_fixed_path"`
	RedirectTrailingSlash bool `yaml:"redirect_trailing_slash"`
	RemoveExtraSlash      bool `yaml:"remove_extra_slash"`
	UseH2C                bool `yaml:"use_h2c"`
	UseRawPath            bool `yaml:"use_raw_path"`
	UnescapePathValues    bool `yaml:"unescape_path_values"`

	// 运行模式.
	//
	//   - debug
	//   - test
	//   - release
	Mode string `yaml:"mode"`
}

// After 后置钩子, 从yaml配置文件加载后执行.
func (o *GinConfig) After() {
	if o.Mode = strings.ToLower(o.Mode); o.Mode == "" {
		o.Mode = DefaultGinMode
	}
}

// Load 从yaml配置文件加载配置参数.
func (o *GinConfig) Load() *GinConfig {
	_ = config.Seek("gin.yaml", "gin.yml").ScanYaml(o)
	return o
}
